Page({
  data: {
    indexImgArr: [{
      id: 0,
      hadimg: false,
      defaultSrc: '/images/add.png',
      src: ''
    }, {
      id: 1,
      hadimg: false,
      defaultSrc: '/images/add.png',
      src: ''
    }, {
      id: 2,
      hadimg: false,
      defaultSrc: '/images/add.png',
      src: ''
    }],
    moreImgArr: []
  },

  //添加图片
  imgAdd: function(e) {
    const self = this;
    const id = e.currentTarget.dataset.id;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths;
        self.setData({
          [`indexImgArr[${id}].src`]: tempFilePaths
        });
        console.log(self.data.indexImgArr);
      }
    })
  },

  //更多图片
  imgMore: function() {
    const self = this;
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths;
        for (let i = 0; i < res.tempFilePaths.length; i++) {
          let obj = {
            src: res.tempFilePaths[i]
          }
          self.setData({
            moreImgArr: self.data.moreImgArr.concat(obj)
          });
        }
      }
    })
  },

  // 删除图片
  imgDel: function(e) {
    const self = this;
    const moreImgArr = self.data.moreImgArr;
    const index = e.currentTarget.dataset.id;
    moreImgArr.splice(index, 1);
    self.setData({
      moreImgArr
    });
  },

  //保存
  save: function() {
    // wx.request({
    //   method:'post',
    //   url: '',
    //   header:'Content-Type:text/html;charset=utf-8',
    //   success:function(res){

    //   }
    // })
  },

  onLoad: function(options) {

  },
})